#!/usr/bin/python
# -*- coding:utf-8 -*-
# @File    : 类+迭代器+斐波那契数列.py
# @Time    : 2021-08-20 17:30
# @Author  : Wenbin Lee
# @Contact : 1297792992(QQ)
# @Software: PyCharm

class Finacci(object):
      def __init__(self,num):
          self.num = num
          self.a = 1
          self.b = 1
          self.current_index=0
      def __iter__(self):  #定义迭代器
          return self
      def __next__(self):
         if self.current_index<self.num:
             data = self.a
             self.a,self.b=self.b,self.a+self.b
             self.current_index+=1
             return data
         else:
             raise StopIteration

 if __name__ == '__main__':
     fib = Finacci(5)
     # val = next(fib)
     for value in fib:
         print(value)